package com.vgemv.jsutilitysdkdemo.module.Reminder;

import androidx.recyclerview.widget.RecyclerView;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.View;
import android.view.Window;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.vgemv.jsutilitysdk.Display.JsActivityContentDisplayManager.*;
import com.vgemv.jsutilitysdk.geometry.JsGeometryManager;
import com.vgemv.jsutilitysdk.log.JsLogManager;
import com.vgemv.jsutilitysdk.Menu.JsMenuView.JsMenuItemStyleDefault;
import com.vgemv.jsutilitysdk.Menu.JsMenuView.JsMenuItemVm.JsMenuItemVm;
import com.vgemv.jsutilitysdk.Menu.JsMenuFragment.JsMenuFragment.JsMenuFragment;
import com.vgemv.jsutilitysdk.Menu.JsMenuView.JsMenuView;
import com.vgemv.jsutilitysdk.Menu.JsMenuView.JsMenuViewAdapter;
import com.vgemv.jsutilitysdk.Menu.JsMenuView.JsMenuViewBasicCallback;
import com.vgemv.jsutilitysdk.Menu.JsMenuView.JsMenuViewVm;
import com.vgemv.jsutilitysdk.Reminder.JsReminderManager;
import com.vgemv.jsutilitysdk.Menu.JsMenuView.JsMenuItemView.JsMenuItemView;
import com.vgemv.jsutilitysdk.Menu.JsMenuView.JsMenuItemVm.JsMenuItemVmDefault;


import java.util.ArrayList;

public class ReminderActivity extends Activity {


    public Handler mHandler = new Handler(Looper.getMainLooper());

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);



        LinearLayout linearLayout = new LinearLayout(this);
        linearLayout.setId(View.generateViewId());
        setContentView(linearLayout);


        JsMenuFragment menuFragment = new JsMenuFragment();
        menuFragment.moveToParentView(this,linearLayout);

        final int itemSize = JsGeometryManager.pixelFromDp(80);

        menuFragment.mBasicCallback = new JsMenuViewBasicCallback() {
            @Override
            public JsMenuViewAdapter jsMenuViewSetAdapter(JsMenuView menuView) {
                return null;
            }

            @Override
            public void jsMenuItemViewWillDisplay(RecyclerView.ViewHolder viewHolder, int position) {

            }

            @Override
            public Rect jsMenuViewSetItemOffset(JsMenuView view, int index) {
                int spanCount = view.mMenuViewVm.mi_spanCount;
                int hPadding = (JsGeometryManager.getScreenSizeInPixel().getWidth() - spanCount * itemSize)/(spanCount + 2);
                int vPadding = JsGeometryManager.pixelFromDp(20);

                Rect rect = new Rect();
                if(index == 0) {
                    rect.top = vPadding;
                    rect.left = hPadding;
                    rect.right = hPadding;
                    rect.bottom = vPadding;
                }
                else if(index == view.vms().size() - 1) {
                    rect.top = vPadding;
                    rect.left = hPadding;
                    rect.right = hPadding;
                    rect.bottom = vPadding;
                }
                else {
                    rect.top = vPadding;
                    rect.left = hPadding;
                    rect.right = hPadding;
                    rect.bottom = vPadding;
                }
                return rect;

            }

            @Override
            public JsMenuViewVm jsMenuViewSetVm(JsMenuView f) {
                JsMenuViewVm vm = new JsMenuViewVm();
                vm.mi_spanCount = 4;
                return vm;
            }

            @Override
            public JsMenuItemView jsMenuViewCreateItemView(JsMenuView f, Context context) {
                return null;
            }

            @Override
            public void jsMenuViewAfterCreateView(JsMenuView fragment) {

            }

            @Override
            public ArrayList<JsMenuItemVm> jsMenuViewSetDatasource() {
                ArrayList<JsMenuItemVm> models = new ArrayList<JsMenuItemVm>();

                JsMenuItemStyleDefault style = new JsMenuItemStyleDefault();
                style.mI_backgroundColor = Color.BLACK;
                style.mI_titleTextColor = Color.WHITE;
                style.mi_height = itemSize;
                style.mi_width = itemSize;

                {
                    JsMenuItemVmDefault vm =  new JsMenuItemVmDefault(0,"DisplayLoadingReminder","",itemSize,itemSize);
                    vm.setStyle(style);
                    models.add(vm);
                }
                {
                    JsMenuItemVmDefault vm =  new JsMenuItemVmDefault(1,"UnDisplayLoadingReminder","",itemSize,itemSize);
                    vm.setStyle(style);
                    models.add(vm);
                }
                {
                    JsMenuItemVmDefault vm =  new JsMenuItemVmDefault(2,"Info","",itemSize,itemSize);
                    vm.setStyle(style);
                    models.add(vm);
                }
                {
                    JsMenuItemVmDefault vm =  new JsMenuItemVmDefault(3,"Warn","",itemSize,itemSize);
                    vm.setStyle(style);
                    models.add(vm);
                }
                {
                    JsMenuItemVmDefault vm =  new JsMenuItemVmDefault(4,"Error","",itemSize,itemSize);
                    vm.setStyle(style);
                    models.add(vm);
                }
                {
                    JsMenuItemVmDefault vm =  new JsMenuItemVmDefault(5,"Success","",itemSize,itemSize);
                    vm.setStyle(style);
                    models.add(vm);
                }
                {
                    JsMenuItemVmDefault vm =  new JsMenuItemVmDefault(6,"ForceUndisplayReminder","",itemSize,itemSize);
                    vm.setStyle(style);
                    models.add(vm);
                }
                {
                    JsMenuItemVmDefault vm =  new JsMenuItemVmDefault(7,"A long text","",itemSize,itemSize);
                    vm.setStyle(style);
                    models.add(vm);
                }
                {
                    JsMenuItemVmDefault vm =  new JsMenuItemVmDefault(8,"A short text","",itemSize,itemSize);
                    vm.setStyle(style);
                    models.add(vm);
                }
                return models;
            }

            @Override
            public void jsMenuViewClickItem(JsMenuView fragmentAlpha, int i, JsMenuItemVm model) {
                switch (i) {
                    case 0:{
                        JsLogManager.logc_d("ReminderActivity/jsMenuViewClickItem","%s","Display reminder");
                        JsDisplayStyle style = new JsDisplayStyle();
                        //默认用110dp.居中显示.
                        int size = JsGeometryManager.pixelFromDp(110);
                        RelativeLayout.LayoutParams contentViewInitialLayoutParams = new RelativeLayout.LayoutParams(size, size);
                        contentViewInitialLayoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
                        style.mRelativeLayoutParams_contentViewInitialLayoutParams = contentViewInitialLayoutParams;
                        style.isMaskViewClickable = false;
                        style.mb_isMaskViewVisible = false;

                        JsActivityContentDisplayManager.sharedInstance().displayLoadingReminder(ReminderActivity.this,style);

                        break;
                    }
                    case 1:{
                        //break.
                        JsActivityContentDisplayManager.sharedInstance().undisplayLoadingReminder(ReminderActivity.this);
                        break;
                    }
                    case 2: {
                        //Info
                        JsActivityContentDisplayManager.sharedInstance().displayMessage("This is info",ReminderActivity.this, JsReminderManager.JsMessageReminderType.Info);
                       break;
                    }
                    case 3: {
                        //warn
                        JsActivityContentDisplayManager.sharedInstance().displayMessage("This is warn",ReminderActivity.this, JsReminderManager.JsMessageReminderType.Warn);
                        break;
                    }
                    case 4: {
                        //error
                        JsActivityContentDisplayManager.sharedInstance().displayMessage("This is error",ReminderActivity.this, JsReminderManager.JsMessageReminderType.Error);
                        break;
                    }
                    case 5 : {
                        //success
                        JsActivityContentDisplayManager.sharedInstance().displayMessage("This is success",ReminderActivity.this, JsReminderManager.JsMessageReminderType.Success);
                        break;
                    }
                    case 6: {
                        //ForceDisunplay
                        JsActivityContentDisplayManager.sharedInstance().undisplayLoadingReminderForce(ReminderActivity.this);
                        break;
                    }
                    case 7: {
                        //ForceDisunplay
                        JsActivityContentDisplayManager.sharedInstance().displayMessage("This is a long long long long long long long long long long long long long long  success message",ReminderActivity.this);
                        break;
                    }
                    case 8: {
                        //ForceDisunplay
                        JsActivityContentDisplayManager.sharedInstance().displayMessage("Hello",ReminderActivity.this);
                        break;
                    }
                    default:{
                        break;
                    }
                }
            }
        };
    }
}